package com.jd.org.dto;

import com.jd.basic.util.MD5Utils;
import com.jd.basic.util.StrUtils;
import com.jd.org.domain.Employee;
import com.jd.org.domain.Shop;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/*
    店铺入驻的dto
 */
@Data // set get toString
public class ShopSettlementDto {
    // 店铺信息字段
//    @NotNull // 用于对象以及 Long Integer这种
//    @NotEmpty // 用于集合
    @NotBlank(message = "店铺名称不能为空！") // 用于字符串
    private String name;
    @NotBlank(message = "店铺电话不能为空！")
    private String tel;
    @NotBlank(message = "店铺地址不能为空！")
    private String address;
    private String logo;
    // 店长信息字段
    @Valid
    private ShopAdminDto admin;

    public Shop getShop(){
        return Shop
                .builder()
                .name(this.name)
                .address(this.address)
                .logo(this.logo)
                .registerTime(new Date())
                .state(1)
                .tel(this.tel)
                .build();
    }

    public Employee getEmp(){
        String salt = StrUtils.getComplexRandomString(32);
        // 盐值 + 密码
        String pw = MD5Utils.encrypByMd5(salt + "1");
        return Employee.builder()
                .username(this.admin.getUsername())
                .phone(this.admin.getPhone())
                .email(this.admin.getEmail())
                .salt(salt)
                .age(10)
                .password(pw)
                .state(1)
                .build();
    }
}
